<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
request.setAttribute("basePath", basePath);
%>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="shortcut icon" type="image/x-icon" href="/images/favicon.ico"/>
<link rel="stylesheet" type="text/css" href="${basePath}/css/default/om-default.css" />
<link rel="stylesheet" href="${basePath}/css/base.css" />
<link rel="stylesheet" href="${basePath}/css/meroperation.css" />
<link rel="stylesheet" href="${basePath}/css/zTreeStyle/zTreeStyle.css" type="text/css">
<link rel="stylesheet" type="text/css" href="${basePath}/css/grid-extra.css" />
<script type="text/javascript" src="${basePath}/js/jquery.min.js" charset="utf-8"></script>
<script type="text/javascript" src="${basePath}/js/jquery.ztree.all.min.js"></script>
<script type="text/javascript" src="${basePath}/js/operamasks-ui.min.js" charset="utf-8"></script>
<script type="text/javascript" src="${basePath}/js/om-grid.js" charset="utf-8"></script>
<script type="text/javascript" src="${basePath}/js/om-calendar.js" charset="utf-8"></script>
<script type="text/javascript" src="${basePath}/js/util.js"></script>
<script type="text/javascript" src="${basePath}/js/tools.js" charset="utf-8"></script>
<title>Insert title here</title>
<script type="text/javascript">

var setting = {
		check: {
			enable: true
		},
		async: {  
            enable: true,  
            url:"${basePath}/privilege/resource/queryResourceNode.do?roleId=${roleId}",
            
            type: "get"  
        },
		data: {
			simpleData: {
				enable: true,
				idKey: "id",
				pIdKey: "parentId",
			}
		}
	};
	
	$(document).ready(function(){
		//$.fn.zTree.init($("#tree"), setting, zNodes);
		$.fn.zTree.init($("#tree"), setting);  
            setTimeout(function(){  
                 
            },1000);
	});

	function authorizate()
	{
		var treeObj = $.fn.zTree.getZTreeObj("tree");
		var nodes = treeObj.getCheckedNodes(true);
		var resIds ='';
		$.each(nodes , function(idx, node){
			if(node.id)
			{
				resIds+=(node.id+",");
			}
		});
		$.ajax({
			type: "POST",
            url: "${basePath}/privilege/role/authorizate.do",
            data: {roleId:$("#roleId").val(), resourceIds:resIds},
            dataType: "json",
            success: function(data){
            	if(data.success)
            	{
            		alert("授权成功");	
            	}else{
            		alert(data.message);
            	}
            }
		})
	}
	
</script>
	<style type="text/css">
.ztree li span.button.add {margin-left:2px; margin-right: -1px; background-position:-144px 0; vertical-align:top; *vertical-align:middle}
	.ui-search-item tr{height: 60px}
	</style>
</head>
<body>
		<div class='ui-nav fn-clear pl15'>
		    <div class='fn-left ft-14 pt5'><strong>权限管理    > 资源管理</strong></div>
		</div>
		<input type="hidden" id="roleId" name="roleId" value="${roleId}">
		<div width=260px align=center valign=top style="BORDER-RIGHT: #999999 1px dashed">
				<ul id="tree" class="ztree" style="width:260px; overflow:auto;"></ul>
					
				   <center style="margin-top: 30px">                
		             <button id='button' type='button' class='iconrept btn ml3' onclick="authorizate()">
		             				<span></span>授权
		             </button>
	             </center>	
		</div>
 		
</body>
</html>